//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.tedu.controller;


import com.tedu.Common.authentication.CurrentPrincipal;
import com.tedu.Common.web.JsonResult;
import com.tedu.pojo.param.OrderAddNewParam;
import com.tedu.pojo.vo.OrdersListVo;
import com.tedu.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;


@Slf4j
@RestController
@RequestMapping({"/orders"})
@Api(
        tags = {"5. 订单管理"}
)
public class OrdersController {
    @Autowired
    private OrderService orderService;

    @GetMapping({""})
    @ApiOperation("查询订单（用户全部订单）")
    public JsonResult listByOrders(@PathVariable @Range(min = 1L,message = "请提交有的用户id") Long userId) {
        log.debug("开始处理【查询订单列表】的请求，用户：" + userId);
        OrdersListVo orderListVo = orderService.listByUserId(userId);
        return JsonResult.ok(orderListVo);
    }

    @PostMapping({"/creat"})
    @ApiOperation("创建订单")
    public JsonResult add( @ApiIgnore CurrentPrincipal currentPrincipal, @Valid OrderAddNewParam orderAddNewParam) {
        Long aLong = orderService.AddOrders(orderAddNewParam);
        return JsonResult.ok(aLong);
    }
}
